package com.wiz.weixin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.wiz.weixin.mapper.FuellingDataMapper;
import com.wiz.weixin.service.FuellingDataService;
import com.wiz.weixin.to.FuellingDataTO;
import com.wiz.weixin.util.PageView;

/**
 * 加油记录
 * @author xxy
 */
@Service("fuellingDataService")
public class FuellingDataServiceImpl implements FuellingDataService {
	private transient final Logger log = LoggerFactory.getLogger(getClass());
	
	@Resource
	private Gson gson;
	@Resource
	private FuellingDataMapper fuellingDataMapper;
	
	@Override
	public PageView getFuellingDataListByOpenId(String openId,int pageNo,int pageSize) {
		PageView pageView = new PageView(pageSize, pageNo);
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("paging", pageView);
		map.put("openId", openId);
		List<FuellingDataTO> fuellingDatas = fuellingDataMapper.getFuellingDataListByOpenId(map);
		pageView.setRecords(fuellingDatas);
		pageView.setCode(200);
		return pageView;
	}

	@Override
	public PageView getCntFuellingDataByOpenId(String openId, int pageNo, int pageSize) {
		PageView pageView = new PageView(pageSize, pageNo);
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("openId", openId);
		int total = fuellingDataMapper.getCntFuellingData(map);
		long pageCount = 0;
		if(total%pageSize==0){
			pageCount = total/pageSize;
		}else{
			pageCount = total/pageSize+1;
		}
		pageView.setPageCount(pageCount);
		return pageView;
	}

}
